package com.dongdong.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdong.mapper.TbGoodsDescMapper;
import com.dongdong.mapper.TbGoodsMapper;
import com.dongdong.mapper.TbItemMapper;
import com.dongdong.pojo.TbGoods;
import com.dongdong.pojo.TbGoodsDesc;
import com.dongdong.pojo.TbItem;
import com.dongdong.service.GoodsDecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@org.springframework.stereotype.Service
public class GoodsDecServiceImpl implements GoodsDecService {
    @Autowired
    private TbGoodsDescMapper tbGoodsDescMapper;
    @Autowired
    private TbGoodsMapper tbGoodsMapper;
    @Resource
    private TbItemMapper tbItemMapper;

    @Override
    @Transactional
    public int insertInfo(TbGoods tbGoods, TbGoodsDesc tbGoodsDesc, String nickName, List<TbItem> itemList) {
       //先增加tb_goods表 并返回主键
        int i = tbGoodsMapper.insertSelective(tbGoods);
        //增加tb_goods_desc表
        tbGoodsDesc.setGoodsId(tbGoods.getId());
        int i2 = tbGoodsDescMapper.insert(tbGoodsDesc);
        Long goodsId = tbGoods.getId();
        String sellerId = tbGoods.getSellerId();
        int i3 = tbItemMapper.insertByList(goodsId,sellerId,itemList,nickName);

        return 1;
    }

    @Override
    public TbGoodsDesc selectGoodDescBygoodsId(Long goodsId) {
        return tbGoodsDescMapper.selectByPrimaryKey(goodsId);
    }
}
